/*
 * Copyright 2016-2017 TVI Go Easy.
 * Created on 2017/11/7 17:57
 */
package com.gitee.mechanic.core.exception;

import com.gitee.mechanic.core.enums.HttpCode;
import org.apache.commons.lang3.StringUtils;

/**
 * 请在此写下该类的说明
 *
 * @author mechanic
 */
public class SSHException extends SuperRuntimeException {
    public SSHException(HttpCode httpCode) {
        super(httpCode);
    }

    public SSHException(HttpCode httpCode, String message) {
        super(httpCode, message);
    }

    /**
     * 格式化异常信息
     *
     * @param host    主机名
     * @param port    端口
     * @param account 账户
     * @param message 异常信息
     * @return String
     */
    public static String format(String host, int port, String account, CharSequence message) {
        return format(host, port, account, null, message);
    }

    /**
     * 格式化带命令带异常信息
     *
     * @param host    主机名
     * @param port    端口
     * @param account 账户
     * @param cmd     命令
     * @param message 异常信息
     * @return String
     */
    public static String format(
      String host,
      int port,
      String account,
      CharSequence cmd,
      CharSequence message) {
        StringBuilder exception = new StringBuilder();
        exception.append("\nSSH 错误：")
                 .append(message)
                 .append("\n服务器: ")
                 .append(host)
                 .append("\n端口: ")
                 .append(port);

        if (StringUtils.isNotBlank(cmd)) {
            exception.append("\n命令: ")
                     .append(cmd);
        }
        return exception.toString();
    }
}
